Page({
  data: {
    currentTime: '09:45',
    batteryLevel: 72,
    currentTab: 'index'
  },

  onLoad: function() {
    this.updateTime()
    this.updateBatteryLevel()
  },

  onShow: function() {
    this.updateTime()
  },

  updateTime: function() {
    var now = new Date()
    var time = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0')
    this.setData({
      currentTime: time
    })
  },

  updateBatteryLevel: function() {
    var battery = Math.floor(Math.random() * 30) + 50
    this.setData({
      batteryLevel: battery
    })
  },

  navigateToPartner: function() {
    wx.navigateTo({
      url: '../member/member',
      success: function() {
        wx.showToast({
          title: '跳转到合伙人页面',
          icon: 'success'
        })
      }
    })
  },

  navigateToEarning: function() {
    wx.navigateTo({
      url: '../courses/courses',
      success: function() {
        wx.showToast({
          title: '跳转到课程页面',
          icon: 'success'
        })
      }
    })
  },

  navigateToCategory: function(e) {
    var category = e.currentTarget.dataset.category
    console.log('选择分类:', category)
    
    switch(category) {
      case 'headlines':
        wx.navigateTo({
          url: '../courses/courses?category=headlines'
        })
        break
      case 'xianyu':
        wx.navigateTo({
          url: '../courses/courses?category=xianyu'
        })
        break
      case 'community':
        wx.navigateTo({
          url: '../courses/courses?category=community'
        })
        break
      case 'taobao':
        wx.navigateTo({
          url: '../courses/courses?category=taobao'
        })
        break
      case 'douyin':
        wx.navigateTo({
          url: '../courses/courses?category=douyin'
        })
        break
      case 'wechat':
        wx.navigateTo({
          url: '../courses/courses?category=wechat'
        })
        break
      case 'fans':
        wx.navigateTo({
          url: '../courses/courses?category=fans'
        })
        break
      case 'media':
        wx.navigateTo({
          url: '../courses/courses?category=media'
        })
        break
      case 'social':
        wx.navigateTo({
          url: '../courses/courses?category=social'
        })
        break
      case 'all':
        wx.navigateTo({
          url: '../courses/courses'
        })
        break
      default:
        wx.showToast({
          title: '功能开发中',
          icon: 'none'
        })
    }
  },

  navigateToCourse: function(e) {
    var course = e.currentTarget.dataset.course
    console.log('选择课程:', course)
    
    wx.navigateTo({
      url: '../courses/courses?course=' + course,
      success: function() {
        wx.showToast({
          title: '跳转到课程详情',
          icon: 'success'
        })
      }
    })
  },

  onSearchTap: function() {
    wx.showToast({
      title: '搜索功能开发中',
      icon: 'none'
    })
  },

  onBannerTap: function() {
    wx.navigateTo({
      url: '../member/member',
      success: function() {
        wx.showToast({
          title: '查看会员优惠',
          icon: 'success'
        })
      }
    })
  },

  onAnnouncementTap: function() {
    wx.showToast({
      title: '查看公告详情',
      icon: 'none'
    })
  },

})
